=[ public: simple $N-arg builtin $FUNC, scope $SC ]

+[ builtin functions ]
C= closure_new(simple_builtin_closure);
closure_set(C, "nargs", $N);
closure_set(C, "func", _bfs_$FUNC);
register_builtin_func( -[stringify $FUNC] ,C,-[stringify $SC]);
+[end]

+[private functions]
static void _bfs_$FUNC( parser_t* parser -[ SB/print $N args ] ) ;
+[end]

static void _bfs_$FUNC( parser_t* parser -[ SB/print $N args ] ) 

=[ public : SB/print $N args ]
	![perl]
		for($i=1;$i<=$N;$i++)
		{ printf( ",utermlist_t * a%d",$i); }
	![end]
=[]


=[ public: builtin[$FLG] $FUNC ]
+[ builtin functions ]
	register_builtin_func(-[stringify $FUNC],
		closure_new(_bf_$FUNC_$UNIQ_closure),
			-[stringify $FLG] );
+[end]
-[closure _bf_$FUNC_$UNIQ , begin ]
	-[ arg parser : parser_t* ]
	-[ arg success : int *]
	-[ function is private ]
	-[ closure is private ]
-[end]

=[]

=[ public: $MATCH= $REST ~ $FMT ]
	+[ private variables ]
	static utermlist_t *clause_$UNIQ;
	+[end]
	+[ pfunc init ]
	clause_$UNIQ= ulang_parse_string($FMT);
	+[ end ]
	$MATCH= match_pattern(clause_$UNIQ, $REST);
=[]



=[ public: low level builtin $FUNC:$N, begin ] 
	-[ closure _bf_$FUNC_$UNIQ, begin ]
		-[ arg parser : parser_t* ]
		-[ arg success : int* ]
		-[ function is private ]
		-[ closure is private ]
		-[ arg codelist : codelist_t* ]
	-[ end ]
	{
		![perl]
		if ($N!=0) {
			printf("utermlist_t *args[%d];\n",$N);
			printf("get_n_args(parser, %d, args);\n",$N);
		}
		![end]
		*success= 1;
		do {
=[ public: low level builtin $FUNC:$N, end ] 
		} while(0);
	}

	+[ builtin functions ]
		C= closure_new(_bf_$FUNC_$UNIQ_closure);
		pflist_append(uglobal_context,
			pfunc_new(pfunc_builtin,
				-[stringify $FUNC], &L,C));

		C2= closure_new(compile_and_run_assembly_closure);
		closure_set(C2, "compiler", C);
		pflist_append(global_context,
			pfunc_new(pfunc_builtin,
				-[stringify $FUNC], &L,C2));
	+[ end ]

=[]




=[ public: simple compiler for $INST with $N args ]
	code_t *C;
	C= code_new( code_$INST, $N );
	![perl]
	for($i=0;$i<$N;$i++) {
	   printf("utermlist_to_carg(parser,args[%d], &C->args[%d]);\n",
			$i,$i);
	}
	![end]
	codelist_append(codelist,C);

=[]

